package com.imoblife.brainwavestus.customview;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.util.DisplayMetrics;

public class BasicDisplay {

	public Activity mActivity;

	public BasicDisplay(Activity activity) {
		mActivity = activity;
		setRequestedOrientation();
	}

	public void setContentView(int layoutResID) {
		mActivity.setContentView(layoutResID);
	}

	/**
	 * ������Ļ����
	 */
	public void setRequestedOrientation() {

		// �����ƽ��������Ϊ����
		if (isXLargerScreen()) {

			if (mActivity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
				mActivity
						.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
			}

			// ����Ϊ����
		} else {

			if (mActivity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
				mActivity
						.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
			}

		}

	}

	/**
	 * �ж��Ƿ�Ϊƽ��
	 * 
	 * @return
	 */
	public boolean isXLargerScreen() {

//		if (VERSION.SDK_INT < 11) {
//			return false;
//		}

		DisplayMetrics displayMetrics = mActivity.getResources()
				.getDisplayMetrics();

		// System.out.println("xdpi" + displayMetrics.xdpi);
		// System.out.println("ydpi" + displayMetrics.ydpi);

		float maxW = displayMetrics.widthPixels < displayMetrics.heightPixels ? displayMetrics.widthPixels
				: displayMetrics.heightPixels;

		maxW /= displayMetrics.density;
		maxW += 0.5;

		System.out.println("maxW=" + maxW + " displayMetrics.density="
				+ displayMetrics.density);

		return maxW >= 552;

	}

	public int dpTopx(int dp) {
		DisplayMetrics displayMetrics = mActivity.getResources()
				.getDisplayMetrics();
		return (int) (dp * displayMetrics.density + 0.5);
	}

	
	
	
}
